<template>
	<view class="my-content">
		<view class="form-box">
			<text class="form-title">*公司名称</text>
			<view class="form-item">
				<input type="text" v-model="formData.company_name" placeholder="请输入公司名称" />
			</view>
		</view>

		<view class="form-box">
			<text class="form-title">法人名称</text>
			<view class="form-item">
				<input type="text" v-model="formData.name" placeholder="请输入法人名称" />
			</view>
		</view>
		
		<view class="form-box">
			<text class="form-title">联系人名称</text>
			<view class="form-item">
				<input type="text" v-model="formData.contact_name" placeholder="请输入联系人名称" />
			</view>
		</view>

		<view class="form-box">
			<text class="form-title">联系人电话</text>
			<view class="form-item">
				<input type="text" v-model="formData.contact_mobile" placeholder="请输入联系人电话" />
			</view>
		</view>

		<view class="form-box" >
			<view class="form-title1">
				<text>上传营业执照照片</text>
				<view class="card-box" @click="uploadImg">
					<image v-if="formData.image" :src="imgDomain+formData.image" style="width: 200rpx;height: 200rpx;"></image>
					<image v-else :src="imgDomain+'uploads/no_data.jpg'" style="width: 200rpx;height: 200rpx;"></image>
				</view>
			</view>
		</view>
		
		<button v-if="formData.status==''" class="submit" @click="submit(formData.status)" style="margin-left: 0rpx;">提交</button>
		<button v-if="formData.status=='1'" class="submit" @click="submit(formData.status)" style="margin-left: 0rpx;">待审核，重新提交</button>
		<button v-if="formData.status=='2'" class="submit" @click="submit(formData.status)" style="margin-left: 0rpx;">审核通过</button>
		<button v-if="formData.status=='3'" class="submit" @click="submit(formData.status)" style="margin-left: 0rpx;">审核驳回，重新提交</button>
		
		
	</view>
</template>

<script>
export default {
	data() {
		return {
			imgDomain:'https://xcx.yumeishangmao.com/',
			formData: {
				member_id:'',
				company_name: "", //
				contact_name:"",
				contact_mobile:"",
				image:'',
				name:'',
				id:'',status:''
			},
			item:{},
		}
	},
	onLoad(options) {
		var member = uni.getStorageSync('member')
		var that = this
		if(member){
			that.formData.member_id = member.member_id
		
			that.$api.sendRequest({
				url: '/api/site/memberAgent', 
				data:{
					formData: JSON.stringify(that.formData)
				},
				success: res => {
					if(res&&res.data){
						that.formData = res.data
					}
				}
			})
		}
		
	},
	methods: {
		submit(type) {
			var that = this
			if (!uni.getStorageSync('memberInfo')) {
				uni.showToast({
					'title':'请先登录'
				})
				return
			}
			uni.showModal({
			  title: '操作确认', // 标题文字，支持字符串或空值
			  content: '确定执行此操作吗？', // 正文内容，支持换行符\r\n
			  showCancel: true, // 是否显示取消按钮（默认true）
			  cancelText: '取消', // 取消按钮文字（默认"取消"）
			  cancelColor: '#999', // 取消按钮文字颜色（默认#000）
			  confirmText: '确定', // 确认按钮文字（默认"确定"）
			  confirmColor: '#007AFF', // 确认按钮颜色（默认#3CC51F）
			  success: res => {
			    if (res.confirm) {

					if (type==2) {
						uni.showModal({
							'content':'审核已通过，不用重复提交'
						})
						return
					}
					if (!this.formData.company_name) {
						uni.showModal({
							content:'请输入公司名称'
						})
						return;
					}
					if (!this.formData.name) {
						uni.showModal({
							content:'请输入法人名称'
						})
						return;
					}
					if (!this.formData.contact_name) {
						uni.showModal({
							content:'请输入联系人名称'
						})
						return;
					}
					if (!this.formData.contact_mobile) {
						uni.showModal({
							content:'请输入联系人电话'
						})
						return;
					}
					
					if (!this.formData.image) {
						uni.showModal({
							content:'请上传营业执照'
						})
						return;
					}
					
					uni.showLoading({
						title: '加载中...',
						mask: true
					});
					
					that.$api.sendRequest({
						url: '/api/site/AgentSave', 
						data:{
							formData: JSON.stringify(that.formData)
						},
						success: res => {
							console.log(res)
						}
					})
					uni.showToast({
						title:'操作成功'
					})
					
					setTimeout(() => {
						uni.navigateBack();	
					}, 1500);
					
					
					uni.hideLoading();
				}
				}
			})
		},
		uploadImg() {
			var that = this
			console.log('上传')
			uni.chooseImage({
				count: 1,
				success: (res) => {
					console.log(res)
					that.uploadImgSubmit(res.tempFilePaths[0])
				},fail(res) {
					console.log(res)
				}
			})
		},
		
		uploadImgSubmit(url) {
			var that = this
			uni.uploadFile({
				url: this.imgDomain+"/index/index/upload",
				filePath: url,
				name: 'file',
				success: (res) => {
					that.formData.image = res.data
				}
			})
		}
	}
}
</script>

<style lang="less" scoped>
	.mask {
		position: fixed;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 10;
	}
.my-content {
	width: 100%;
	padding: 30upx;
	box-sizing: border-box;

	.form-box {
		width: 100%;
		border-radius: 16upx;
		box-shadow: 0px 8px 20px 0px rgba(0, 0, 0, 0.3);
		margin-bottom: 20upx;
		padding: 30upx;
		box-sizing: border-box;

		.form-title {
			font-size: 32upx;
			color: #000;
			font-weight: 700;
			display: block;
		}

		.form-title1 {
			font-size: 32upx;
			color: #000;
			font-weight: 700;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.card-box {
			width: 50%;
			margin: 10upx auto;

			image {
				width: 100%;
			}
		}

		.switch-box {
			display: flex;
			align-items: center;

			image {
				width: 44upx;
				height: auto;
				display: block;
				margin-right: 10upx;
			}

			text {
				color: #A6A6A6;
				font-size: 28upx;
				font-weight: normal;

				&:last-of-type {
					color: #3662EC;
				}
			}
		}

		.form-item {
			margin: 20upx 0;
			font-size: 32upx;
			display: flex;
			align-items: center;

			.blue {
				color: #3662EC;
			}

			.font-num {
				color: #999;
				font-size: 28upx;
				text-align: right;
				display: block;
			}

			.picker-box {
				display: flex;
				align-items: center;
				margin-right: 10upx;

				image {
					width: 48upx;
					height: auto;
				}
			}

			input {
				width: 100%;
			}
		}
	}

	.submit {
		width: 100%;
		height: 80upx;
		border-radius: 16upx;
		background: #FF8F1F;
		box-shadow: 0px 8px 20px 0px rgba(0, 0, 0, 0.3);
		color: #fff;
		line-height: 80upx;
		font-size: 44upx;
		font-weight: 700;
		margin-top: 40upx;
	}
}
</style>